package com.huixue.cn.ztej.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huixue.cn.ztej.bean.Mechanical;
import com.huixue.cn.ztej.bean.Results;
import com.huixue.cn.ztej.dao.MechanicalMapper;
import com.huixue.cn.ztej.utils.SystemContents.API_RETURN_STATUS;
import com.huixue.cn.ztej.utils.framwork.PageParameter;

@Service
public class SysMechanicaService {
	
	@Autowired
	MechanicalMapper mechanicalMapper;
	
	public Results listMechanicalPage(Map<String,Object> searchParams,Integer pageNumber, Integer pageSize){
		PageParameter page = new PageParameter();
		page.setCurrentPage(pageNumber);
		page.setPageSize(pageSize);
		searchParams.put("page", page);
		
		
		Map<String, Object> rmap = new HashMap<String, Object>();
		List<Mechanical> list = mechanicalMapper.listMechanicalPage(searchParams);		
		rmap.put("rows", list);
		rmap.put("total", page.getTotalPage());
		rmap.put("page", pageNumber);						//当前页
		rmap.put("records", page.getTotalCount());			//总记录数
		rmap.put("pageSize", pageSize);						//每页个数
		
		Results results = new Results(
				API_RETURN_STATUS.NORMAL.value(),
				API_RETURN_STATUS.NORMAL.desc(),rmap);
		
		return results;
	}
	
	
	public Results listMechanicalType(Integer type){
		List<Mechanical> list = mechanicalMapper.listMechanicalType(type);
		Results results = new Results(
				API_RETURN_STATUS.NORMAL.value(),
				API_RETURN_STATUS.NORMAL.desc(),list);	
		return results;
	}
	
	
	public Mechanical findById(Integer id){
		Mechanical model = mechanicalMapper.findById(id);
		return model;
	}
	
	public void update(Mechanical mechanical){
		mechanicalMapper.update(mechanical);
	}
	
	public void saveMechanical(Mechanical mechanical){
		mechanicalMapper.saveMechanical(mechanical);
	}
	
	public void delete(Integer id){
		mechanicalMapper.delete(id);
	}
}
	

